package com.wen.mall.interceptor;

import com.wen.mall.consts.Mallconst;
import com.wen.mall.exception.UserLoginException;
import com.wen.mall.pojo.User;
import lombok.SneakyThrows;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 温嘉璐
 */
public class UserLoginInterceptor implements HandlerInterceptor {


    @SneakyThrows
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        User user = (User) request.getSession().getAttribute(Mallconst.CURRENT_USER);
        if (user == null) {

            throw new UserLoginException();

        }
        return true;
    }
}
